using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using BaseScripts;

/// <summary>
/// 挂载在Enemy的Zombie儿子上, 用来进行攻击到的触发判定
/// </summary>
public class ZombieAttackTrigger : MonoBehaviour
{
    private Enemy enemy;
    private void Start() {
        enemy = GetComponentInParent<Enemy>();
    }

    private void OnTriggerExit2D(Collider2D other) {
        if(other.gameObject.tag == "Player"){
            var dmg = enemy.GetAttackDamage();
            var force = enemy.GetAttackForce();

            Status status = other.GetComponent<Status>();
            status.AddEffect(new Effect(
                status,
                EffectType.NormalDamage,
                new float[]{
                    dmg
                }
            ));

            Vector3 forceDir = (other.transform.position - transform.position).normalized;
            status.AddEffect(new Effect(
                status,
                EffectType.AddForce,
                new float[]{
                    forceDir[0],
                    forceDir[1],
                    forceDir[2],
                    force,
                }
            ));

            status.AddEffect(new Effect(
                status,
                EffectType.GetHit,
                new float[]{}
            ));
        }
    }
}
